// T4.  The Impact of Distance on Likelihood of Being at Appropriate Grade-for-Age
// T4.  The Impact of Distance on Likelihood of Being at Appropriate Grade-for-Age
// T4.  The Impact of Distance on Likelihood of Being at Appropriate Grade-for-Age


// PRELIMINARIES

clear
set more off
set scheme s1mono


// LOAD DATA
	
use "JakielaOzierFernaldKnauer-preschool-data.dta", replace



** OLS without controls

forvalues i = 3/6 {
	reg grade4age schdist if roundage==`i', cluster(respid)
	mat V = r(table)
	local _beta`i' = string(V[1,1],"%04.3f")
	local _se`i' = string(V[2,1],"%04.3f")
	local _pval`i' = string(V[4,1],"%04.3f")
	if V[4,1] < 0.001 {
		local _pval`i' = "p$<$0.001"
	}
	local _obs`i' = e(N)
}
cap file close fh
file open fh using "out/T4-grade4age1.tex", write replace

file write fh "At or above appropriate grade-for-age level & `_beta3' & `_beta4' & `_beta5' & `_beta6'  \\  " _newline
file write fh "		    & (`_se3') & (`_se4') & (`_se5') & (`_se6')  \\  " _newline
file write fh "		    & [`_pval3'] & [`_pval4'] & [`_pval5'] & [`_pval6']  \\  " _newline

file close fh


** OLS with controls

local controls "i.childage haz male cgmom momeduc momluo hhsize sibs numassets haz_imputed dadabsent dadeduc dadluo missing_data i.schoolid"

forvalues i = 3/6 {
	reg grade4age schdist `controls' if roundage==`i', cluster(respid)
	mat V = r(table)
	local _beta`i' = string(V[1,1],"%04.3f")
	local _se`i' = string(V[2,1],"%04.3f")
	local _pval`i' = string(V[4,1],"%04.3f")
	if V[4,1] < 0.001 {
		local _pval`i' = "p$<$0.001"
	}
}

cap file close fh
file open fh using "out/T4-grade4age2.tex", write replace

file write fh "At or above appropriate grade-for-age level & `_beta3' & `_beta4' & `_beta5' & `_beta6'  \\ " _newline
file write fh "		    & (`_se3') & (`_se4') & (`_se5') & (`_se6')  \\ " _newline
file write fh "		    & [`_pval3'] & [`_pval4'] & [`_pval5'] & [`_pval6']  \\ " _newline

file close fh

cap file close fh

file open fh using "out/T4-grade4ageinfo.tex", write replace

file write fh "Obs. & `_obs3' & `_obs4' & `_obs5' & `_obs6'  \\  " _newline

file close fh
